package biz.datalk.industrialland.admin.config.properties;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author tarofang@163.com
 * @date 2020-06-24
 */
@ConfigurationProperties(TaskScheduleExecutorProperties.PREFIX)
@Getter
@Setter
@ToString
public class TaskScheduleExecutorProperties extends ExecutorProperties implements InitializingBean {
    public static final String PREFIX = "executor.task-schedule";
    /** 同一时刻，最大线程执行数 */
    private int semaphoreNum = 4;

    /** 限速器 每秒最多允许同时执行线程数 */
    private int rateLimiterPermitsPerSecond = 4;

    @Override
    public void afterPropertiesSet() throws Exception {
        if (StringUtils.equals(this.getThreadNamePrefix(), DEFAULT_THREAD_NAME_PREFIX)) {
            this.setThreadNamePrefix("ADMIN-TASK-SCHEDULE-");
        }
        if (this.getTransferRequestAttributes() == null) {
            this.setTransferRequestAttributes(Boolean.FALSE);
        }
    }
}
